package com.lu.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lu.mapper.KeywordMatchSimpleMapper;
import com.lu.model.entity.KeywordMatchSimple;
import com.lu.service.KeywordMatchSimpleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 关键词匹配 服务实现类
 * </p>
 *
 * @author zhanglu
 * @since 2022-09-14
 */
@Service
public class KeywordMatchSimpleServiceImpl extends ServiceImpl<KeywordMatchSimpleMapper, KeywordMatchSimple> implements KeywordMatchSimpleService {

    @Override
    public List<KeywordMatchSimple> listBySource(String code, String keyword) {
        //检查是否存在
        QueryWrapper<KeywordMatchSimple> simpleQueryWrapper = new QueryWrapper<>();
        simpleQueryWrapper.eq("code", code);
        if(ObjectUtil.isNotEmpty(keyword)){
            simpleQueryWrapper.likeRight("source_py", keyword).or().likeRight("source_py_fl", keyword).or().like("source", keyword);
        }
        simpleQueryWrapper.last("limit 20");
        List<KeywordMatchSimple> keywordMatchSimples = this.baseMapper.selectList(simpleQueryWrapper);
        return keywordMatchSimples;
    }

}
